'''
@Company: TWL
@Author: xue jian
@Email: xuejian@kanzhun.com
@Date: 2020-06-23 14:33:15
'''

class DateRange:
    def __init__(self, bgn, end):
        import datetime
        bgn = bgn.split('-')
        begin = datetime.date(int(bgn[0]), int(bgn[1]), int(bgn[2]))
        end = end.split('-')
        end = datetime.date(int(end[0]), int(end[1]), int(end[2]))
        d = begin
        delta = datetime.timedelta(days=1)
        self.dates = []
        while d <= end:
            self.dates.append(d.strftime("%Y-%m-%d"))
            d += delta
        # return re

class CutData:
    def __init__(self, num, from_path, write_path, dates):
        self.num = num
        self.from_path = from_path
        self.write_path = write_path
        self.dates = dates
        if self.from_path[-1] != '/':
            self.from_path += '/'
        if self.write_path[-1] != '/':
            self.write_path += '/'

    def excute(self):
        import random, os
        import sys
        for date in self.dates:
            print(date)
            if not os.path.exists(self.write_path + date):
                os.mkdir(self.write_path + date)
            cut_files = []
            for i in range(self.num):
                cut_files.append(open(self.write_path + date + "/" + str(i), 'wb'))
            f = open(self.from_path + date, 'rb')
            count = 0
            for line in f:
                tmp_num = count//10000 % self.num
                cut_files[tmp_num].write(line)
                count += 1



if __name__=='__main__':
    data_range = DateRange('2020-6-1', '2020-06-13')
    